# -*- coding: utf-8 -*-
"""
Date: 2021-03-26
Author: J z
"""
from common.service_config import get_action_id
from pyshare.const.enums.payment import UnlockType
from pyshare.game_logs.cross_siegelord_log import CrossSiegelordVitLog, CrossSiegelordPersonScoreLog, \
    CrossSiegelordPrestigeLog, CrossSiegelordCoinLog
from pyshare.const.enums.cross_siegelord_enum import SiegelordVitLogDict


class SiegelordShopMixin(object):
    __slots__ = ()
    activity_id = NotImplemented
    shop_id = NotImplemented
    buy_type = NotImplemented
    cost_num = NotImplemented
    limit_times = NotImplemented
    limit_type = NotImplemented
    buff = NotImplemented

    def change_shop_price(self, val):
        """ 修改商品价格 """
        self.cost_num = val
        self.save()


class SiegelordShopGiftMixin(object):
    __slots__ = ()
    activity_id = NotImplemented
    shop_id = NotImplemented
    limit_times = NotImplemented
    limit_type = NotImplemented
    gift_id = NotImplemented
    gift_type = NotImplemented
    chest_id = NotImplemented

    def change_chest_id(self, val):
        """ 修改商品价格 """
        self.chest_id = val
        self.save()


class SiegelordShopRoleMixin(object):
    __slots__ = ()
    activity_id = NotImplemented
    rid = NotImplemented
    shop_buy_stat = NotImplemented
    shop_gift_buy_stat = NotImplemented

    def update_shop_buy_stat(self, val):
        """ 更新普通商城购买记录 """
        self.shop_buy_stat = val
        self.save()

    def update_shop_gift_buy_stat(self, val):
        """ 更新现金商城购买记录 """
        self.shop_gift_buy_stat = val
        self.save()


class CrossSiegelordMiXin(object):

    field_id = NotImplemented
    role_guid = NotImplemented
    vit = NotImplemented
    coin = NotImplemented
    limit_cash_task_stat = NotImplemented
    royal_stage_award_list = NotImplemented
    person_score = NotImplemented
    prestige = NotImplemented

    def cost_role_coin(self, val):
        """ 购买消耗玩家货币数量 """
        self.coin -= val
        self.save()

    def clear_role_coin(self):
        """清空玩家货币"""
        self.coin = 0
        self.save()

    def clear_role_limit_cash_task_process(self):
        """清空玩家限时现金触发进度"""
        self.limit_cash_task_stat = []
        self.save()

    def clear_royal_stage_award_list(self):
        """清空玩家阶段奖励领取列表"""
        self.royal_stage_award_list = []
        self.save()

    def role_vit_log(self, val):
        """
        体力日志
        :param val:
        :return:
        """
        add_vit = val - self.vit.remaining
        if add_vit == 0:
            return

        scene = get_action_id()
        if scene in [43210, 43213] and add_vit > 0:
            remark = SiegelordVitLogDict.get(str(scene), '获取备注失败') + "补偿"
        else:
            remark = SiegelordVitLogDict.get(str(scene), '获取备注失败')

        try:
            CrossSiegelordVitLog.log_game(self.role_guid, val, add_vit, scene, remark)
        except:
            pass

    # def person_score_value_log(self, val):
    #     """
    #     个人积分日志
    #     :param val: 积分数值
    #     :return:
    #     """
    #     add_score_value = val - self.person_score
    #     if add_score_value == 0:
    #         return
    #     try:
    #         CrossSiegelordPersonScoreLog.log_game(self.role_guid, val, add_score_value)
    #     except:
    #         pass

    def prestige_value_log(self, val):
        """
        个人威望值日志
        :param val: 威望值数值
        :return:
        """
        add_score_value = val - self.prestige
        if add_score_value == 0:
            return
        try:
            CrossSiegelordPrestigeLog.log_game(self.role_guid, val, add_score_value)
        except:
            pass

    def coin_value_log(self, val):
        """
        商城货币值日志
        :param val: 威望值数值
        :return:
        """
        add_coin_value = val - self.coin
        if add_coin_value == 0:
            return
        try:
            CrossSiegelordCoinLog.log_game(self.role_guid, val, add_coin_value)
        except:
            pass

    @property
    def is_unlock_special_award(self):
        """
        特殊奖励是否解锁
        :return:
        """
        from pyshare.dal.repository_impl import RechargeUnlockRepository

        unlock_type = 0
        primary_record_count = RechargeUnlockRepository.get_count_by_rid_unlockid_actid(self.role_guid,
                                                                                        UnlockType.CrossSiegelordPrimaryAward,
                                                                                        self.field_id)
        if primary_record_count:
            unlock_type = UnlockType.CrossSiegelordPrimaryAward
        advance_record_count = RechargeUnlockRepository.get_count_by_rid_unlockid_actid(self.role_guid,
                                                                                        UnlockType.CrossSiegelordAdvancedAward,
                                                                                        self.field_id)
        if advance_record_count:
            unlock_type = UnlockType.CrossSiegelordAdvancedAward
        return unlock_type


class CrossSiegelordReceiveVitRecordMixin(object):
    __slots__ = ()
    affair_id = NotImplemented
    field_id = NotImplemented
    activity_id = NotImplemented
    role_guid = NotImplemented
    receive_vit = NotImplemented

    def add_receive_vit(self, val):
        """ 增加领取体力次数 """
        self.receive_vit += val
        self.save()





